// ==UserScript==
// @name           phpBB FBC Duplicate Jumpbox
// @namespace      http://glenncarr.com/greasemonkey/phpbb/fbc
// @description    Copy the 'Jump to:' from the top of the forum to the bottom
// @include        *fantasybaseballcafe.com/forums/*
// @author         Glenn Carr (glenn at glenncarr dot com)
// $LastChangedRevision: 141 $
// $LastChangedDate: 2007-06-21 17:19:33 +0000 (Thu, 21 Jun 2007) $
// ==/UserScript==
/*

Updates:
    21-Jun-2007 - Remove currently defective 2nd jumpbox so there aren't two at the bottom of the page.

*/

(function(){

var jumpBoxForms = document.evaluate( '//form[@id="jumpbox"]', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );

// No jumpbox to duplicate, so bail
if ( jumpBoxForms.snapshotLength == 0 )
    return;

// Find the place to insert the duplicate, bail if we can't find it.
var topicActions = document.evaluate( '//div[@class="topic-actions"]', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
if ( topicActions.snapshotLength < 2 )
    return;
    
// If there is more than one, *CURRENTLY*, the last one doesn't work, so kill it...
if ( jumpBoxForms.snapshotLength > 1 )
{
    for ( var i = 1; i < jumpBoxForms.snapshotLength; i++ )
    {
        var doomedForm = jumpBoxForms.snapshotItem( i );
        doomedForm.parentNode.removeChild( doomedForm );
    }
}

GM_addStyle( '\
.gncThisWorks { font-style: italic; font-weight: bold; }\
' );

// We're gonna clone the first one, but perform some necessary surgery on our clone...
var jumpBox = jumpBoxForms.snapshotItem( 0 );

var newjb = document.createElement( 'form' );
newjb.id = 'jumpbox_gnc';
newjb.innerHTML = jumpBox.innerHTML.replace( "forms['jumpbox']", "forms['jumpbox_gnc']" ).replace( /(jump to:)/i, '<span class="gncThisWorks">Really</span> $1' );
var re = /jumpbox/g;
newjb.setAttribute( "onsubmit", jumpBox.getAttribute( "onsubmit" ).replace( re, 'jumpbox_gnc' ) );
newjb.setAttribute( "action", jumpBox.getAttribute( "action" ).replace( re, 'jumpbox_gnc' ) );
newjb.setAttribute( "method", jumpBox.getAttribute( "method" ).replace( re, 'jumpbox_gnc' ) );

var lastTopicActions = topicActions.snapshotItem( 1 );
lastTopicActions.parentNode.insertBefore( newjb, lastTopicActions.nextSibling );

})();